package com.wuchao.servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

/**
 * @author 吴超66
 * @version 1.0
 * @date 2022/4/20 14:07
 */
@WebFilter(filterName = "Filter1",
        urlPatterns = "/demo5/*",initParams = @WebInitParam(name = "code",value = "utf-8"))
public class Filter1 implements Filter {
    private  String code=null;
    public void destroy() {
        this.code=null;
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        String characterEncoding = req.getCharacterEncoding();
        if(characterEncoding==null||!characterEncoding.equals("utf-8")){
            req.setCharacterEncoding("utf-8");
        }
        chain.doFilter(req, resp);//过滤器
    }

    public void init(FilterConfig config) throws ServletException {
        String code = config.getInitParameter("code");
        this.code=code;

    }

}
